package com.company.eduservice.controller.front;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.company.eduservice.entity.EduCourse;
import com.company.eduservice.entity.EduTeacher;
import com.company.eduservice.service.EduCourseService;
import com.company.eduservice.service.EduTeacherService;
import com.company.utils.R;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/eduservice/teacherfront")
@CrossOrigin
public class IndexTeacherShow {

    @Resource
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;

    @GetMapping("/getTeacherFrontList/{current}/{limit}")
    @ApiOperation(value = "分页获取讲师列表(前端展示)")
    public R pageTeacherList(@PathVariable Long current, @PathVariable Long limit) {
        Page<EduTeacher> page = new Page<>(current, limit);
        Map<String, Object> map = teacherService.pageTeacherList(page);
        return R.ok().data(map);
    }

    //讲师详情功能 + 讲师所讲的课程信息
    @GetMapping("/getTeacherFrontInfo/{teacherId}")
    public R getTeacherFrontInfo(@PathVariable String teacherId) {
        EduTeacher teacher = teacherService.getById(teacherId);
        List<EduCourse> list = courseService.getCourseByTeacherId(teacherId);

        return R.ok().data("teacher", teacher).data("courseList", list);
    }

}
